package com.hgz;

import java.io.IOException;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import com.hgz.util.Constant;
import com.hgz.util.OperateTime;
import com.hgz.util.ReadAndWriteFile;

public class UrlFecth {

	public String testWrite(String url,String filePath){
		try {
			WriteLocalFileFromGetDateFormOtherUrl(url,filePath);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}
	public void WriteLocalFileFromGetDateFormOtherUrl(String url,String filePath) throws IOException{
		Document doc;
		doc = Jsoup.connect(url).get();
		Elements trContents  = doc.select("tr[class=formlist_tr]");
		 String fileName = OperateTime.getDate()+""+".txt";
		 filePath= filePath +fileName;
		for (Element trContent : trContents){
			System.out.println (trContent.text());
			String brName = trContent.text();
		//	String [] names = brName.split(" ");
//			for(int i=0;i< names.length;i++){
//				Item item = new Item();
//				item.setName("土豆");
//				item.setMinPrice("1.0");
//				item.setPrice("1.5");
//				item.setMaxPrice("2.0");
//				item.setDw("斤");
//
//			}
//	System.out.println(names.length);
			ReadAndWriteFile.javaWriteFile(filePath,brName);
		}
	}
	public static void main(String args[]){
		System.out.println(new UrlFecth().testWrite(Constant.FECTH_URL,Constant.DATA_PATH));
	}
	
}

